home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 February: Tool Chest / Dev.CD Feb 94.toast / Tool Chest / Development Platforms / AppsToGo / AppsToGo.src / DTS.Lib / DTS.Lib.headers / Utilities.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-18  |  36.4 KB  |  850 lines  |  [TEXT/MPS ]

  1. /*-----------------------------------------------------------------------------------------
  2. #
  3. #    Apple Macintosh Developer Technical Support
  4. #
  5. #    Collection of Utilities for DTS Sample code
  6. #
  7. #    Program:    Utilities.c.o
  8. #    File:        Utilities.h    -    Header for C Source
  9. #
  10. #    Copyright © 1988-1990 Apple Computer, Inc.
  11. #    All rights reserved.
  12. #
  13. -----------------------------------------------------------------------------------------*/
  14.  
  15. #ifndef __UTILITIES__
  16. #define __UTILITIES__
  17.  
  18. #ifdef applec
  19.  
  20. #    ifndef __TYPES__
  21. #        include <Types.h>
  22. #    endif
  23.  
  24. #    ifndef __QUICKDRAW__
  25. #        include <QuickDraw.h>
  26. #    endif
  27.  
  28. #    ifndef __DIALOGS__
  29. #        include <Dialogs.h>
  30. #    endif
  31.  
  32. #    ifndef __FILES__
  33. #        include <Files.h>
  34. #    endif
  35.  
  36. #    ifndef __MEMORY__
  37. #        include <Memory.h>
  38. #    endif
  39.  
  40. #    ifndef __MENUS__
  41. #        include <Menus.h>
  42. #    endif
  43.  
  44. #    ifndef __OSUTILS__
  45. #        include <OSUtils.h>
  46. #    endif
  47.  
  48. #    ifndef __WINDOWS__
  49. #        include <Windows.h>
  50. #    endif
  51.  
  52. #endif
  53.  
  54.  
  55. #include "UtilitiesCommon.h"
  56. #ifndef __STRINGUTILS__
  57. #include "StringUtils.h"
  58. #endif
  59.  
  60.  
  61. struct PopupCtlData {
  62.     MenuHandle        mHandle;
  63.     short            mID;
  64.     char            mPrivate[1];
  65. };
  66. typedef struct PopupCtlData PopupCtlData;
  67. typedef PopupCtlData *PopupCtlDataPtr, **PopupCtlDataHandle;
  68. #define    kMenuItemTxtInsert    -1
  69. #define    kMenuItemNumInsert    -2
  70. #define kMenuItemSectionEnd    -3
  71.  
  72. /*-----------------------------------------------------------------------------------------
  73.     Global constants
  74. -----------------------------------------------------------------------------------------*/
  75. #ifndef applec
  76.  
  77. #ifndef nil
  78. #define nil    0L
  79. #endif
  80.  
  81. #ifndef _WaitNextEvent
  82. #define _WaitNextEvent    0xA860
  83. #endif
  84.  
  85. #ifndef _InitGraf
  86. #define _InitGraf        0xA86E
  87. #endif
  88.  
  89. #ifndef _Unimplemented
  90. #define _Unimplemented    0xA89F
  91. #endif
  92.  
  93. /*
  94. #define screenActive            15
  95. */
  96. #endif
  97.  
  98. #define    kNoEvents                0            /* no events mask */
  99. #define kDelayTime                4            /* For the delay time when flashing the
  100.                                                menubar and highlighting a button.
  101.                                                4/60ths of a second*/
  102.  
  103. #define kStartPtH                2            /* offset from the left of the screen */
  104. #define kStartPtV                2            /* offset from the top of the screen */
  105. #define kStaggerH                12            /* staggering amounts for new windows */
  106. #define kStaggerV                16
  107.  
  108. #define chHome                    '\001'        /* ASCII code for the Home key */
  109. #define chEnter                    '\003'        /* ASCII code for Enter character */
  110. #define chEnd                    '\004'        /* ASCII code for the End key */
  111. #define chHelp                    '\005'        /* ASCII code for Help key */
  112. #define chBackspace                '\010'        /* ASCII code for Backspace character */
  113. #define chTab                    '\011'        /* ASCII code for Tab character */
  114. #define chPageUp                '\013'        /* ASCII code for Page Up key */
  115. #define chPageDown                '\014'        /* ASCII code for Page Down key */
  116. #define chReturn                '\015'        /* ASCII code for Return character */
  117. #define chFunction                '\020'        /* ASCII code for any function key */
  118. #define chClear                    '\033'        /* ASCII code for Clear key (aka ESC) */
  119. #define chEscape                '\033'        /* ASCII code for Escape (aka Clear) key */
  120. #define chLeft                    '\034'        /* ASCII code for left arrow */
  121. #define chRight                    '\035'        /* ASCII code for right arrow */
  122. #define chUp                    '\036'        /* ASCII code for up arrow */
  123. #define chDown                    '\037'        /* ASCII code for down arrow */
  124. #define chFwdDelete                '\177'        /* ASCII code for forward delete */
  125. #define chSpace                    ' '            /* ASCII code for Space character */
  126.  
  127. enum { kQDOriginal = 0, kQD8Bit, kQD32Bit };    /* For use with gQDVersion */
  128.  
  129. /*-----------------------------------------------------------------------------------------
  130.     Types
  131. -----------------------------------------------------------------------------------------*/
  132.  
  133. typedef short *IntegerPtr, **IntegerHandle;
  134.  
  135. typedef long *LongintPtr, **LongintHandle;
  136.  
  137. typedef Boolean *BooleanPtr, **BooleanHandle;
  138.  
  139. #ifndef THINK_C
  140. typedef Rect *RectPtr, **RectHandle;
  141. #endif
  142.  
  143. struct    WindowTemplate    {                    /*template to a WIND resource*/
  144.     Rect    boundsRect;
  145.     short    procID;
  146.     Boolean    visible;
  147.     Boolean    filler1;
  148.     Boolean    goAwayFlag;
  149.     Boolean    filler2;
  150.     long    refCon;
  151.     Str255    title;
  152. };
  153. typedef    struct    WindowTemplate    WindowTemplate;
  154. typedef            WindowTemplate    *WindowTPtr, **WindowTHndl;
  155.  
  156. /* following is here to account for lapses in the THINK C headers */
  157.  
  158. #ifndef applec
  159. #ifndef THINK_C
  160. /*
  161. typedef unsigned char TrapType;
  162. */
  163. struct NumVersion {
  164.     unsigned char majorRev;         /* 1st part of version number in BCD*/
  165. /*    unsigned short minorRev : 4;        2nd part is 1 nibble in BCD*/
  166. /*    unsigned short bugFixRev : 4;         3rd part is 1 nibble in BCD*/
  167.     unsigned char minorAndBugFixRev;
  168.     unsigned char stage;            /*stage code: dev, alpha, beta, final*/
  169.     unsigned char nonRelRev;        /*revision level of non-released version*/
  170. };
  171.  
  172. typedef struct NumVersion NumVersion;
  173. /* Numeric version part of 'vers' resource */
  174. struct VersRec {
  175.     NumVersion numericVersion;        /*encoded version number*/
  176.     short countryCode;                /*country code from intl utilities*/
  177.     Str255 shortVersion;            /*version number string - worst case*/
  178.     Str255 reserved;                /*longMessage string packed after shortVersion*/
  179. };
  180. typedef struct VersRec VersRec;
  181. typedef VersRec *VersRecPtr, **VersRecHndl;
  182.  
  183.  
  184. #define Length(string) (*(unsigned char *)(string))
  185. #define Gestalt            GESTALT
  186. #define NewGestalt        NEWGESTALT
  187. #define ReplaceGestalt    REPLACEGESTALT
  188. #endif
  189. #endif
  190.  
  191.  
  192. typedef Rect (*PositionWndProcPtr)(WindowPtr window, WindowPtr relatedWindow, Rect sizeInfo);
  193.  
  194.  
  195. typedef struct PFSSpec {
  196.     FSSpec    fss;
  197.     Str31    volName;
  198. } PFSSpec;
  199. typedef PFSSpec *PFSSpecPtr;
  200.  
  201. typedef struct ControlStyleInfo {
  202.     short    ctlID;
  203.     short    fontSize;
  204.     Style    fontStyle;
  205.     Str32    font;
  206.     Str63    keyEquivs;
  207.     Str255    balloonHelp;
  208. } ControlStyleInfo;
  209. typedef ControlStyleInfo *ControlStyleInfoPtr;
  210.  
  211.  
  212.  
  213. /*-----------------------------------------------------------------------------------------
  214.     Handy Macros/inlines
  215. -----------------------------------------------------------------------------------------*/
  216. #ifdef false                                        /* The c++ stuff is turned OFF!!! */
  217.  
  218. inline Point* TopLeft(Rect& r)                        /* provide access to rect.topLeft  */
  219. {    return (Point*)(&r.top); }
  220.  
  221. inline Point* BotRight(Rect& r)                        /* provide access to rect.botRight  */
  222. {    return (Point*)(&r.bottom); }
  223.  
  224. inline short HiWrd(long aLong)                        /* return the hi word of a long */
  225. {    return ((aLong >> 16) & 0xFFFF); }
  226.  
  227. inline short LoWrd(long aLong)                        /* return the lo word of a long */
  228. {    return (aLong & 0xFFFF); }
  229.  
  230. inline void SETPT(Point *pt,short h,short v)
  231. {    (*pt).h = h; (*pt).v = v); }
  232.  
  233. inline void SETRECT(Rect *r,short left,short top,short right,short bottom)
  234. {    SETPT(TopLeft(*r), left, top); SETPT(BotRight(*r), right, bottom); }
  235.  
  236. /* 
  237.  *    Useful functions for testing gestalt attribute responses
  238.  *
  239.  *    BTstBool returns a true boolean value (0 or 1), but is slower than:
  240.  *    BTstQ which simply returns a non-zero value if the bit is set which
  241.  *    means the result could get lost if assigned to a short, for example.
  242.  *
  243.  *    arg is any integer value, bitnbr is the number of the bit to be tested.
  244.  *    bitnbr = 0 is the least significant bit.
  245.  */
  246. inline short BTstBool(arg, bitnbr)    
  247. {    return ((arg >> bitnbr) & 1); }
  248.  
  249. inline long BTstQ(arg, bitnbr)
  250. {    return (arg & (1 << bitnbr)); }
  251.  
  252. #else
  253.  
  254.  
  255. #ifndef THINK_C
  256. #define QD(whatever) (qd.##whatever)
  257. #else
  258. #define QD(whatever) (whatever)
  259. #endif
  260.  
  261.  
  262. #define TopLeft(r)        (* (Point *) &(r).top)
  263. #define BotRight(r)        (* (Point *) &(r).bottom)
  264. #define HiWrd(aLong)    (((aLong) >> 16) & 0xFFFF)
  265. #define LoWrd(aLong)    ((aLong) & 0xFFFF)
  266. #define MIN(a, b) ((a) < (b) ? (a) : (b) )
  267. #define MAX(a, b) ((a) > (b) ? (a) : (b) )
  268. #define SETPT(pt, x, y)    (*(pt)).h = (x); (*(pt)).v = (y)
  269. #define SETRECT(r, left, top, right, bottom)    \
  270.                         SETPT(&TopLeft(*(r)), (left), (top)); \
  271.                         SETPT(&BotRight(*(r)), (right), (bottom))
  272. /* 
  273.  *    Useful macros for testing gestalt attribute responses
  274.  *
  275.  *    BTstBool returns a true boolean value (0 or 1), but is slower than:
  276.  *    BTstQ which simply returns a non-zero value if the bit is set which
  277.  *    means the result could get lost if assigned to a short, for example.
  278.  *
  279.  *    arg is any integer value, bitnbr is the number of the bit to be tested.
  280.  *    bitnbr = 0 is the least significant bit.
  281.  */
  282. #define BTstBool(arg, bitnbr)    ((arg >> bitnbr) & 1)
  283. #define BTstQ(arg, bitnbr)        (arg & (1 << bitnbr))
  284.  
  285. #endif
  286.  
  287. /*-----------------------------------------------------------------------------------------
  288.     Global variables
  289. -----------------------------------------------------------------------------------------*/
  290. /*    The following global variables are initialized by StardardInitialization to
  291.  *    define the environnment.  This used to be a single SysEnvRec, but now,
  292.  *    all those variables defined in a SysEnvRec can be returned by Gestalt
  293.  *    (except sysVRefNum; see FindSysFolder).  Note that all the variables
  294.  *    below will be correctly initialized whether Gestalt is available or not;
  295.  *    the Gestalt glue handles this.
  296.  */
  297. extern short            gMachineType;            /* which machine this is */
  298. extern short            gSystemVersion;            /* System version number */
  299. extern short            gProcessorType;            /* which CPU this is */
  300. extern Boolean            gHasFPU;                /* true if machine has an FPU */
  301. extern short            gQDVersion;                /* major QD version #; 0 for original, 
  302.                                                     1 for color QD, 2 for 32-bit QD */
  303. extern short            gKeyboardType;            /* which type of keyboard is present */
  304. extern short            gAppleTalkVersion;        /* AppleTalk version number */
  305.         
  306. /*    These are also handled by Gestalt. gHasPMMU has no corresponding SysEnvRec
  307.  *    field, but it is handled by the glue, so we include it here for completeness.
  308.  *    gAUXVersion will be initialized with Gestalt if present, but correctly
  309.  *    set even if Gestalt is not available
  310.  */
  311. extern Boolean            gHasPMMU;                /* true if machine has a PMMU or equivalent */
  312. extern short            gAUXVersion;            /* major A/UX version number (0 if not present) */
  313.  
  314. /*    
  315.  *    gHasWaitNextEvent is set to TRUE if the Macintosh we are running on has
  316.  *    WaitNextEvent implemented. We can use this in our main event loop to
  317.  *    determine whether to call WaitNextEvent or GetNextEvent.
  318.  */
  319. extern Boolean            gHasWaitNextEvent;
  320.  
  321. /*
  322.  *    gAppResRef is the application’s resource file reference. I need to save
  323.  *    this since I can open other resource files. The current resource file is
  324.  *    always gAppResRef unless I momentarily set it to another file to read its
  325.  *    resources, and then immediately restore it back.
  326.  */
  327. extern short            gAppResRef;
  328.  
  329. /*
  330.  *    gInBackground is maintained by our osEvent handling routines. Any part of
  331.  *    the program can check it to find out if it is currently in the background.
  332.  */
  333. extern Boolean            gInBackground;            /* maintained by StandardInitialization
  334.                                                       and DoEvent */
  335.                                                       
  336. /*
  337.  *    gAppName holds the name of the application that's running. You can use if
  338.  *    for any purpose you'd like. It is also used by StandardAbout if it can't
  339.  *    find a string to use for the application name in a resource, so make sure
  340.  *    you call InitForStandardAbout if you are going to call StandardAbout. If you
  341.  *    call StandardInitialization, this is done for you.
  342.  */
  343. extern Str255            gAppName;
  344.  
  345. /*
  346.  *    gSignature holds the creator signature for the running application. It follows the
  347.  *    same rules as those for gAppName.
  348.  */
  349. extern OSType            gSignature;
  350.  
  351. /*
  352.  *    Initial values of these global variables are set to zero or FALSE by MPW's 
  353.  *    runtime initialization routines.  If the Utilities initialization routines
  354.  *    have been properly called, then gUtilitiesInited will be true.  If it is
  355.  *    not true, then the values of the above global variables are invalid.
  356.  */
  357. extern Boolean            gUtilitiesInited;
  358.  
  359. /*-----------------------------------------------------------------------------------------
  360.     Interface to routines
  361. -----------------------------------------------------------------------------------------*/
  362.  
  363. #ifdef __cplusplus
  364. extern "C" {
  365. #endif
  366.  
  367. Rect        SetWindowPlacementRect(Rect *rct);
  368.             /* Set the window placement rect.  This rect overrides normal window positioning
  369.                in favor of the rect passed in.  For reference, the function also returns the
  370.                old window placement rect.  If nil is passed in for the new rect, then no
  371.                change to the positioning rect is made.  The old rect is still returned. */
  372.  
  373. short        CenteredAlert(short alertID, WindowPtr relatedWindow, ModalFilterProcPtr filter);
  374.             /* Given an Alert ID and a related window pointer, this routine will center
  375.                the alert on the same device as the related window.  If the related
  376.                window pointer is nil, then the alert will be centered on the device
  377.                that the alert would normally be placed if Alert was called directly. */
  378.  
  379. void        CenterRectInRect(Rect outerRect, Rect *innerRect);
  380.             /* Given two rectangles, this routine centers the second one within the first. */
  381.  
  382. Rect        CenterWindow(WindowPtr window, WindowPtr relatedWindow, Rect sizeInfo);
  383.             /* Given a window pointer and a related window pointer, this routine will
  384.                center the window on the same device as the related window.  If the
  385.                related window pointer is nil, then the window will be centered on the
  386.                device that the window already is.
  387.                WARNING: This routine may move or purge memory. */
  388.  
  389. void        CloseAnyWindow(WindowPtr window);
  390.             /* Closes the indicated window.  Does the right thing, taking into account
  391.                that the window may belong to a DA.
  392.                WARNING: An application window is closed via a CloseWindow call.  Use
  393.                            this call when you want to keep the storage for the window
  394.                         record.  (Compare against DisposeAnyWindow.) */
  395.  
  396. void        DisposeAnyWindow(WindowPtr window);
  397.             /* Disposes of the indicated window.  Does the right thing, taking into account
  398.                that the window may belong to a DA.
  399.                WARNING: An application window is closed via a DisposeWindow call.  Use
  400.                            this call when you want to free up the storage for the window
  401.                         record.  (Compare against CloseAnyWindow.) */
  402.  
  403. void        DeathAlert(short errResID, short errStringIndex);
  404.             /* Display an alert that tells the user an error occurred, then exit the
  405.                program. This routine is used as an ultimate bail-out for serious errors
  406.                that prohibit the continuation of the application. */ 
  407.  
  408. void        DeathAlertMessage(short errResID, short errStringIndex, short message);
  409.  
  410. void        ErrorAlert(short errResID, short errStringIndex);
  411.  
  412. void        ErrorAlertMessage(short errResID, short errStringIndex, short message);
  413.  
  414. OSErr        FindSysFolder(short *foundVRefNum, long *foundDirID);
  415.             /* FindSysFolder returns the (real) vRefNum, and the DirID of the current
  416.                system folder.  It uses the Folder Manager if present, otherwise
  417.                it falls back to SysEnvirons.  It returns zero on success, otherwise
  418.                a standard system error. */
  419.  
  420. Handle        GetAppIndResource(ResType theType, short index, OSErr *err);
  421.             /* GetAppIndResource gets a resource from the application's res file by index */
  422.  
  423. Handle        GetAppNamedResource(ResType theType, StringPtr name, OSErr *err);
  424.             /* GetAppNamedResource gets a resource from the application's res file by name */
  425.  
  426. Handle        GetAppResource(ResType theType, short theID, OSErr *err);
  427.             /* GetAppResource gets a resource from the application's res file by resource ID */
  428.  
  429. short        GetAUXVersion( void);
  430.             /* getAUXVersion -- Checks for the presence of A/UX by whatever means is
  431.                appropriate.  Returns the major version number of A/UX (i.e. 0 if A/UX 
  432.                is not present, 1 for any 1.x.x version 2 for any 2.x version, etc.
  433.                This code should work for all past, present and future A/UX systems. */
  434.  
  435. short        GetButtonVariant(ControlHandle ctl);
  436.                 /* This function returns which kind of button the control is.  This does more
  437.                 ** than GetCVariant in that it makes sure that the control is actually a
  438.                 ** button.  It does this by comparing the defProc against the known defProc
  439.                 ** for the various button types.  For 7.0, there is only one defProc for all
  440.                 ** variants, but for pre-7.0, there is one defProc value for each variant.
  441.                 ** The method below handles either case. */
  442.  
  443. OSErr        SimpleCanDialog(void);
  444.             /* Check to see if dialogs are allowed.  They may not be if AppleScript is
  445.                running the show. */
  446.  
  447. DialogPtr    GetCenteredDialog(short id, DialogPtr storage, WindowPtr relatedWindow, WindowPtr behind);
  448.             /* Given a dialog ID and a related window pointer, this routine will center
  449.                the dialog on the same device as the related window.  If the related
  450.                window pointer is nil, then the dialog will be centered on the device
  451.                that the dialog would normally be placed if GetNewDialog was called. */
  452.  
  453. WindowPtr    GetCenteredWindow(short id, Ptr storage, Boolean vis, WindowPtr relWindow,
  454.                               WindowPtr behind, Boolean inColor, Rect sizeInfo, long refCon);
  455.             /* Given a window ID and a related window pointer, this routine will center
  456.                the window on the same device as the related window.  If the related
  457.                window pointer is nil, then the window will be centered on the device
  458.                that the window would normally be placed if GetNewWindow was called.  The
  459.                function is also passed the sizeInfo rect, which holds min and max size
  460.                information for the window.  (See GetSomeKindOfWindow.) */
  461.  
  462. Boolean     GetCheckOrRadio(DialogPtr dlgPtr, short itemNo);
  463.  
  464. long        GetGestaltResult(OSType gestaltSelector);
  465.             /* GetGestaltResult returns the result value from Gestalt for the specified
  466.                selector.  If Gestalt returned an error GetGestaltResult returns zero.  Use 
  467.                of this function is only cool if we don't care whether Gestalt returned an 
  468.                error.  In many casesyou may need to know the exact Gestalt error code so 
  469.                then this routine would be inappropriate. */
  470.  
  471. Point        GetGlobalMouse(void);
  472.             /* Returns the location of the mouse in local coordinates. It does this by
  473.                calling OSEventAvail(). */ 
  474.  
  475. Point        GetGlobalTopLeft(WindowPtr window);
  476.             /*     Given a window, this will return the top left point of the window’s port in
  477.                   global coordinates. Something this doesn’t include, is the window’s drag
  478.                   region (or title bar). This returns the top left point of the window’s
  479.                   content area only. */
  480.  
  481. long        GetKFreeSpace(short vRefNum);
  482.  
  483. Rect        GetMainScreenRect(void);
  484.  
  485. GDHandle    GetRectDevice(Rect globalRect);
  486.             /* Find the greatest overlap device for the given global rectangle.
  487.             ** This function assumes that you have a system that GDHandle can happen.
  488.             ** If you call this function on other QuickDraws, you will crash. */
  489.  
  490. Rect        GetRectDeviceRect(Rect globalRect);
  491.             /* Find the rect of the greatest overlap device for the given global rect. */
  492.  
  493. WindowPtr    GetSomeKindOfWindow(PositionWndProcPtr whatKind, short windID, Ptr storage,
  494.                                 Boolean vis, WindowPtr relatedWindow, WindowPtr behind,
  495.                                 Boolean inColor, Rect sizeInfo, long refCon);
  496.             /* Given a window positioning procedure pointer, a window ID and a window
  497.                pointer the window relates to, this function open a new window by either
  498.                a NewCWindow or a NewWindow call, depending on the value of inColor.  The
  499.                window will be opened invisible, independent of what the resource says.
  500.                Once the window is opened successfully, the positioning procedure is
  501.                called.  The positioning procedure is passed a pointer to the just-opened
  502.                invisible window,a pointer to the related window, and the sizeInfo rect.
  503.                The sizeInfo rect holds the minimum size in the upper-left point, and the
  504.                max size in the lower-left point.  It is up to the positioning procedure
  505.                to move the invisible window to the correct location on the correct device.
  506.                Once the positioning procedure returns, the window will be made visible if
  507.                so indicated by the resource. */
  508.  
  509. WindowPtr    GetStaggeredWindow(short id, Ptr storage, Boolean vis, WindowPtr relWindow,
  510.                                WindowPtr behind, Boolean inColor, Rect sizeInfo, long refCon);
  511.             /* Given a window ID and a window pointer the window relates to, this function
  512.                will stagger the window’s rectangle before showing it on the proper screen.
  513.                This follows the Apple Human Interface Guidelines for where to place a
  514.                staggered window on the screen.  If the window is not closely associated
  515.                with another window, pass a nil for the window pointer of the related
  516.                window.  If you pass a nil, the window is simply displayed where the
  517.                resource would indicate.  The function is also passed the sizeInfo rect, which
  518.                holds min and max size information for the window.  (See GetSomeKindOfWindow.) */
  519.  
  520. void        GetSystemInfo(void);
  521.             /* This sets up some global variables for use by the utilities package and
  522.                your application.  If you call StandardInitialization, you don't need to
  523.                call this, as it will do it for you. */ 
  524.  
  525. TrapType    GetTrapType(short theTrap);
  526.             /* Returns the type (OSType or ToolType) of the trap. It does this by checking
  527.                the bits of the trap word. */ 
  528.  
  529. Rect        GetWindowContentRect(WindowPtr window);
  530.             /* Given a window pointer, return the global rectangle that encloses the
  531.                content area of the window. */
  532.  
  533. short        GetWindowCount(Boolean includeDAs, Boolean includeDLOGs, Boolean includeInvisibles);
  534.             /* This procedure counts the number of windows in the application plane.  You have the
  535.                choices of also counting DAs, DLOGs, and invisible windows in this count. */
  536.  
  537. GDHandle    GetWindowDevice(WindowPtr window);
  538.             /* Find the greatest overlap device for the given window. */
  539.  
  540. Rect        GetWindowDeviceRect(WindowPtr window);
  541.             /* Given a window pointer, find the device that contains most of the window
  542.                and return the device's bounding rectangle. */
  543.  
  544. Rect        GetWindowDeviceRectNMB(WindowPtr window);
  545.             /* Given a window pointer, find the device that contains most of the window
  546.                and return the device's bounding rectangle.  If this device is the main
  547.                device, then remove the menubar area from the rectangle. */
  548.  
  549. Rect        GetWindowStructureRect(WindowPtr window);
  550.             /* This procedure is used to get the rectangle that surrounds the entire
  551.                structure of a window.  This is true whether or not the window is visible.
  552.                If the window is visible, then it is a simple matter of using the bounding
  553.                rectangle of the structure region.  If the window is invisible, then the
  554.                strucRgn is not correct.  To make it correct, then window has to be moved
  555.                way off the screen and then made visible.  This generates a valid strucRgn,
  556.                although it is valid for the position that is way off the screen.  It still
  557.                needs to be offset back into the original position.  Once the bounding
  558.                rectangle for the strucRgn is obtained, the window can then be hidden again
  559.                and moved back to its correct location.  Note that ShowHide is used,
  560.                instead of ShowWindow and HideWindow.  HideWindow can change the plane of
  561.                the window.  Also, ShowHide does not affect the hiliting of windows. */
  562.   
  563. void        GlobalToLocalRect(Rect *aRect);
  564.  
  565. void        InitToolBox(void);
  566.  
  567. Boolean        IsAppWindow(WindowPtr window);
  568.             /* Returns TRUE if the windowKind of the window is greater than or equal to
  569.                userKind. If it is less, or the window is NIL, then return FALSE. */ 
  570.  
  571. Boolean        IsDAWindow(WindowPtr window);
  572.             /* Returns TRUE if the windowKind of the window is less than zero. If not, or
  573.                the window is NIL, then return FALSE. */ 
  574.  
  575. Boolean        IsScrollBar(ControlHandle ctl);
  576.             /* Returns TRUE if the control is a scrollbar. */
  577.  
  578. void        LocalToGlobalRect(Rect *aRect);
  579.  
  580. char        LockHandleHigh(Handle theHandle);
  581.             /* Does a MoveHHi on the handle and then locks it.  Also, the original state
  582.                of the handle is returned, so you can keep it and set the handle back to it's
  583.                original state with a HSetState call. */
  584.  
  585. short        NumToolboxTraps(void);
  586.             /* Determines the size of the Tool trap table. It does this by sampling a
  587.                couple of trap locations and seeing which, if any are Unimplemented. */ 
  588.  
  589. void        OutlineControl(ControlHandle button);
  590.  
  591. void         OutlineDialogItem(DialogPtr dlgPtr, short item);
  592.  
  593. void        PositionRectInRect(Rect outerRect, Rect *innerRect, Fixed horzRatio, Fixed vertRatio);
  594.             /* Given two rectangles, this routine positions the second within the first one
  595.                so that the it maintains the spacing specified the the horzRatio and vertRatio
  596.                parameters. In other words, to center an inner rectangle hoizontally, but
  597.                have its center be 1/3 from the top of the outer rectangle, call this
  598.                routine with horzRatio = FixRatio(1, 2), vertRatio = FixRatio(1, 3). */
  599.  
  600. void        PullApplicationToFront(void);
  601.             
  602. void        SelectButton(ControlHandle button);
  603.             /* Given the button control handle, this will cause the button to look as if it
  604.                has been clicked in. This is nice to do for the user if they type return or
  605.                enter to select the default item. */
  606.  
  607. void        SetCheckOrRadioButton(DialogPtr dlgPtr, short itemNo, short state);
  608.  
  609. Rect        StaggerWindow(WindowPtr window, WindowPtr relatedWindow, Rect sizeInfo);
  610.             /* This algorithm for staggering windows does quite a good job.  It also is
  611.                quite gnarly.  Here's the deal:
  612.                There are pre-designated positions that we will try when positioning a
  613.                window.  These slots will be tried from the upper-left corner towards the
  614.                lower-right corner.  If there are other windows in that slot, then we will
  615.                consider that slot taken, and proceed to the next slot.  A slot is
  616.                determined to be taken by checking a point with a slop area.  This slop
  617.                area is diamond-shaped, not simply rectangular.  If there is no other
  618.                visible window with an upper-left corner within the slopt diamond, then
  619.                we are allowed to position our window there.
  620.                The above rule holds true unless this forces the window to be partly
  621.                off the screen.  If the window ends up partly off the screen, then we give
  622.                up and just put it in the first slot. */
  623.  
  624. void        StandardAbout(short appNameStringID);
  625.             /* Shows a standard about box with the name of the application, its version
  626.                number, a copyright notice, and DTS credits. Most of this information is
  627.                taking from a standard DITL and the application’s 'vers' resource. The name
  628.                of the application is taken either from the 'STR ' resource passed in to
  629.                this routine, or from GetAppParms() if that resource doesn’t exist, or you
  630.                pass in -1. */ 
  631.  
  632. void        StandardInitialization(short callsToMoreMasters);
  633.             /* Initializes “gInBackGround” to FALSE. Makes the following InitXXX calls:
  634.                InitGraf(), InitFonts(), InitWindows(), InitMenus(), TEInit(),
  635.                InitDialogs(), InitCursor(). Brings application to front with 3 EventAvail
  636.                calls. Calls SysEnvirons to initialize “gMac”. Calls TrapExists() to
  637.                initialize “gHasWaitNextEvent”. */ 
  638.    
  639. void        StandardMenuSetup(short MBARID, short AppleMenuID);
  640.             /* Installs and draws the menus indicated by 'MBAR'(MBARID). Adds DA’s to the
  641.                menu indicated by AppleMenuID by calling AddResMenu. If the menuBar cannot
  642.                be created, the alert specified by rDeathAlert is displayed. */   
  643.  
  644. void        InsertHierMenus(MenuHandle menu);
  645.             /* Look through the menu items for hierarchical references.  For each found,
  646.                insert the hierarchical menu, and then recursively search that menu for
  647.                hierarchical menus.  This function is called by StandardMenuSetup so that
  648.                all hierarchical menus are inserted at application startup time. */
  649.  
  650. void         ToggleCheck(DialogPtr dlgPtr, short cChkItem);
  651.  
  652. Boolean        TrapExists(short theTrap);
  653.                 /* Returns TRUE if the trap exists (i.e., it’s callable without getting DS
  654.                    error 12) */ 
  655.  
  656. Boolean        WhichControl(Point mouseLoc, long when, WindowPtr window, ControlHandle *ctlHit);
  657.                 /* Returns which visible control mouseLoc is within, independent of
  658.                    the state of the control.  Scrollbars that are inactive are not
  659.                    found by FindControl. */
  660.  
  661. void        ZoomToWindowDevice(WindowPtr window, short maxWidth, short maxHeight,
  662.                                short zoomDir, Boolean front);
  663.  
  664.  
  665.  
  666. pascal Boolean    AlertFilter(DialogPtr dlg, EventRecord *event, short *item);
  667. /* The alert filter makes sure that that the outline for the button gets
  668. ** redrawn.  This is important if balloon help is on, as the balloon window
  669. ** can overlap the outline of the button and leave a portion of it erased. */
  670.  
  671. pascal Boolean    KeyEquivFilter(DialogPtr dlg, EventRecord *event, short *item);
  672. /* The key equivalent filter allows you to assign key equivalents to dialog
  673. ** items.  Each item can have as many key equivalents as you wish.  You can
  674. ** also specify the exact state of the modifiers that you will or won't allow.
  675. ** The key equivalent information is stored in the resource fork, so the
  676. ** key equivalents can be easily localized.
  677. ** This code expects the key equivalents to be in item #2, which is a StatText
  678. ** item that is located so the text is outside of the dialog.  This allows us
  679. ** to put key equivalent information in the resource fork, so the key
  680. ** equivalents are localizable.
  681. **
  682. ** An example save changes before closing or quitting res source with
  683. ** keyEquiv info would look like:
  684. **
  685. ** resource 'DITL' (rYesNoCancel, purgeable) {
  686. **     {
  687. **         {71, 315, 91, 367}, Button     { enabled, "Save" },
  688. **         {0, -1000, 20, 2},  StaticText { disabled,
  689. **             "=S190001,=s190001,=D190003,=d190003,=.190104,1B190004" },
  690. **         {71, 80, 91, 162},  Button { enabled, "Don’t Save" },
  691. **         {71, 244, 91, 302}, Button { enabled, "Cancel" },
  692. **         {11, 78, 61, 366},  StaticText { disabled,
  693. **             "Save changes to the document “^0” before ^1?" },
  694. **         {11, 23, 43, 55},        Icon { disabled, 2 }
  695. **     }
  696. ** };
  697. **
  698. ** The document name would be the string for param #0.
  699. ** The text "closing" or "quitting" would be the string for param #1.
  700. **
  701. ** The keyEquiv entry is item #2, which has a rect that pushes it out of the
  702. ** dialog.  The string info is interpreted as to what the key/modifier combo
  703. ** is, and what dialog item it relates to.
  704. **
  705. ** A single key equiv entry is 8 characters.  Entries are separated by commas.
  706. **
  707. ** If the first character of an entry is an =, then the next character is the 
  708. ** key.  If the first character isn't an =, then the first two characters are 
  709. ** the hex value of the key.  (Ex:  =S or =s for save, 1B for ESC.)
  710. **
  711. ** If the key pressed is the same as the key value for any of the entries, then 
  712. ** the next two characters are the hex value for which modifiers to test.  This
  713. ** modifier test value is anded with the modifier.  The result is then compared 
  714. ** to the value of the next two hex digits.  If they are equal, then the 
  715. ** modifiers are correct, as well as the key.  If this is so, we have a winner.
  716. **
  717. ** "=S190001,=s190001,=D190003,=d190003,=.190104,1B190004"
  718. **
  719. ** The above string breaks down as follows:
  720. ** =S190001  =S  if event keypress is an S, check the modifier values
  721. **           19  check controlKey/optionKey/cmdKey
  722. **           00  all modifiers we are testing for should be false
  723. **           01  if above is true, keypress maps to item # 1
  724. ** =s190001  Same as =S, but lowercase
  725. ** =D190001  Same as =S, but maps to item #3
  726. ** =d190001  Same as =D, but lowercase
  727. ** =.190104  =.  if event keypress is a period, check the modifier values
  728. **           19  check controlKey/optionKey/cmdKey
  729. **           01  controlKey/optionKey should be false, cmdKey should be true
  730. **           04  if above is true, keypress maps to item # 4
  731. ** 1B190004  1B  if event keypress is an ESC, check the modifier values
  732. **           19  check controlKey/optionKey/cmdKey
  733. **           00  all modifiers we are testing for should be false
  734. **           04  if above is true, keypress maps to item # 4
  735. */
  736.  
  737. void            OffsetControl(ControlHandle ctl, short dx, short dy);
  738. /* This function is a convenient way to move a control a specified amount. */
  739.  
  740. void            DoDrawGrowIcon(WindowPtr window, Boolean horLine, Boolean verLine);
  741. /* This function draws the grow icon for the window in the specified manner.  You
  742. ** can clip out the horizontal or vertical line that is also drawn along with
  743. ** the grow icon, or you can have them draw. */
  744.  
  745. void            DoDrawControls(WindowPtr window, Boolean scrollBarsOnly);
  746. /* This function drawn all of the controls in a window, or just the scrollbar
  747. ** controls.  The reason for this function is that scrollbars are really
  748. ** tri-state, especially now with 7.0.  A scrollbar can be hilighted or not,
  749. ** or it can be drawn in a window that isn't the frontmost of the application
  750. ** plane.  DoDrawControls takes this third scrollbar state into consideration. */
  751.  
  752. void            DoDraw1Control(ControlHandle ctl, Boolean scrollBarsOnly);
  753. /* This function is where the work for scrollbar/control drawing is actually
  754. ** done.  DoDrawControls calls this function for each control in a window. */
  755.  
  756. ControlHandle    GetPopupCtlHandle(DialogPtr theDialog, short itemNum);
  757. /* GetPopupCtlHandle takes a dialog and its item number and (assuming it is a
  758. ** popup menu control) and returns the control handle for the popup. */
  759.  
  760. MenuHandle    GetPopupMenuHandle(ControlHandle popupCtl);
  761. /* GetPopupMenuHandle takes a popup control and returns the menu handle from
  762. ** the control. */
  763.  
  764. short    GetPopupCtlValue(DialogPtr theDialog, short popItem);
  765. /* GetPopupCtlValue returns value for the popup control. */
  766.  
  767. void    SetPopupCtlValue(DialogPtr theDialog, short popItem, short value);
  768. /* SetPopupCtlValue makes value the new value for the popup control. */
  769.  
  770. short    SmartInsMenuItem(MenuHandle theMenu, StringPtr theText, short section, short where);
  771. /* This is used to "intelligently" insert a menu item into a menu.  Pass it
  772. ** the menu to be modified, the text of the item being added, plus where the
  773. ** item is to be inserted.  The location to be inserted is described by two
  774. ** parameters:  section & where.
  775. **
  776. ** section:  Indicates which group of menu items you wish to add an item to.
  777. **           Menu item section 1 is all of the items before the first
  778. **           dividing line.  Menu item section 2 is all items after the
  779. **           first dividing line and before the second, and so on.  If you
  780. **           have no dividing lines, you have just 1 section so pass in 1.
  781. **
  782. ** where:    Indicates the item position relative to the section.  To add an
  783. **           item such that it is the first item in a section, pass in a 1.
  784. **           It will be added in front of the first item in the section.
  785. **
  786. **           NOTE:  You should never pass in a section or where parameter of 0.
  787. **
  788. ** Negative values for "where" are magic.  If where = kMenuItemTxtInsert, then
  789. ** it inserts the item alphabetically into the section.  A where of 
  790. ** kMenuItemNumInsert works the same as kMenuItemTxtInsert, except it treats
  791. ** the strings are numbers for comparison purposes.  If you want to add the
  792. ** item to the end of a section, use kMenuItemSectionEnd.
  793. **
  794. ** As a final goodie, SmartInsMenuItem returns the menu item # from the
  795. ** beginning of the menu, not section. */
  796.  
  797. short    CountMSections(MenuHandle theMenu);
  798. /* Return the number of menu sections.  The number of sections is equal to the
  799. ** number of dividing lines + 1. */
  800.  
  801. short    FindMenuItem(MenuHandle theMenu, StringPtr cmpTxt);
  802. /* Find the menu item number, given the text of the menu. */
  803.  
  804. OSErr    PersistFSSpec(PFSSpecPtr pfss);
  805. /* Do what is necessary to get an FSSpec to persist when saved to disk.  The parID
  806. ** will still be valid, along with the file name.  The part that isn't valid is
  807. ** the vRefNum.  This function converts the FSSpec's vRefNum to a volume name, or
  808. ** converts the volume name into a vRefNum.  An extended FSSpec is used.  The
  809. ** extension is, logically enough, a volume name.  If the FSSpec's vRefNum is non-0,
  810. ** then it fills in the volume name for that vRefNum.  If the vRefNum is 0, it then
  811. ** uses the volume name to generate a vRefNum.
  812. ** Prior to saving a PFSSpec to disk, call PersistFSSpec.  It will fill in the
  813. ** volume name.  After having read a PFSSpec from disk, set the vRefNum to 0 and
  814. ** then call PersistFSSpec.  It will fill in the vRefNum that corresponds to the
  815. ** volume name. */
  816.  
  817. StringPtr    PathNameFromDirID(long DirID, short vRefNum, StringPtr str);
  818. /* This function is straight out of tech note #238.  See this note for more info. */
  819.  
  820. void    InitQuickTime(void);
  821. /* Call this to generically initialize QuickTime.  It sets two globals:
  822. **     gQTVersion                    QuickTime version (0 means not available).
  823. **     gMovieControllerComponent    QuickTime movie controller component reference.
  824. */
  825.  
  826. void    MoveStyledControl(ControlHandle ctl, short xloc, short yloc);
  827. void    SizeStyledControl(ControlHandle ctl, short xsize, short ysize);
  828. void    SetStyledCtlValue(ControlHandle ctl, short value);
  829. void    ShowStyledControl(ControlHandle ctl);
  830. void    HideStyledControl(ControlHandle ctl);
  831. void    UseControlStyle(ControlHandle ctl);
  832. void    SetStyledCTitle(ControlHandle ctl, StringPtr title);
  833. short    GetControlID(ControlHandle ctl);
  834. Boolean    GetControlStyle(ControlHandle ctl, ControlStyleInfoPtr cinfo);
  835. OSErr    SetControlStyle(ControlHandle ctl, ControlStyleInfoPtr cinfo);
  836. Boolean    ControlKeyEquiv(WindowPtr window, EventRecord *event, ControlHandle *retCtl, StringPtr defaultEquivs);
  837.     /* These functions are for extending the functionality of controls.  The structure
  838.     ** ControlStyleInfo is appended to a control, immediately after the title field.
  839.     ** This is valid, as the only control manager function that changes the size of a
  840.     ** control is SetCTitle.  (The function SetStyledCTitle is used instead to maintain
  841.     ** the control style info.) */
  842.  
  843.  
  844.  
  845. #ifdef __cplusplus
  846. }
  847. #endif
  848.  
  849. #endif
  850.